/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geergenbein.azw.model.transcription;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 *
 * @author andrew
 */
@Entity
@NamedQuery(name = "findTranscriptionSystem", 
    query = "select ts from TranscriptionSystem ts " +
    "where ts.name = :name and ts.dialect = :dialect")
@Table(name = "transcription_system", 
    uniqueConstraints = @UniqueConstraint(columnNames = {"dialect_id", "name"}))
public class TranscriptionSystem implements Serializable {
    
    private static final long serialVersionUID = 1L;
    private Long id;
    private Dialect dialect;
    private String name;

    public TranscriptionSystem() {
        
    }
    
    public TranscriptionSystem(Dialect dialect, String name) {
        this.dialect = dialect;
        this.name = name;
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Override
    public int hashCode() {
        return new HashCodeBuilder().
                append(dialect).
                append(name).
                hashCode();
    }

    @Override
    public boolean equals(Object object) {
        
        if (this == object) {
            return true;
        }
        
        if (!(object instanceof TranscriptionSystem)) {
            return false;
        }
        
        TranscriptionSystem other = (TranscriptionSystem) object;
        
        return new EqualsBuilder().
                append(dialect, other.getDialect()).
                append(name, other.getName()).
                isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                append(id).
                append(dialect).
                append(name).
                toString();
    }

    @ManyToOne(optional=false)
    @JoinColumn(name = "dialect_id", nullable = false)
    public Dialect getDialect() {
        return dialect;
    }

    public void setDialect(Dialect dialect) {
        this.dialect = dialect;
    }
    
    @Column(length=63, nullable=false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
